cmake_minimum_required(VERSION 3.0.2)
project(flyeye)

find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  geometry_msgs
  mavros_msgs
  nav_msgs
  roscpp
  rospy
  sensor_msgs
  std_msgs
  tf
  tf2
  roslib
  image_transport
)

find_package(PkgConfig REQUIRED)
pkg_check_modules(YAML_CPP REQUIRED yaml-cpp)

set(OpenCV_DIR "/home/firefly/Software/opencv-4.11.0/build")
find_package(OpenCV 4.11 REQUIRED)
# 调试信息
message(STATUS "OpenCV库版本: ${OpenCV_VERSION}")
message(STATUS "OpenCV库路径: ${OpenCV_DIR}")
message(STATUS "OpenCV包含目录: ${OpenCV_INCLUDE_DIRS}")
message(STATUS "OpenCV库文件: ${OpenCV_LIBS}")

set(ZBAR_INCLUDE_DIRS /usr/include)

if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
    set(ZBAR_LIBRARIES /lib/x86_64-linux-gnu/libzbar.so)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
    set(ZBAR_LIBRARIES /lib/aarch64-linux-gnu/libzbar.so)
else()
    message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif()

catkin_package(
)

include_directories(
# include
  ${catkin_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
  ${ZBAR_INCLUDE_DIRS}
  ${YAML_CPP_INCLUDE_DIRS}
  include/
)

add_executable(qr_wcw src/qr_wcw.cpp)
target_link_libraries(qr_wcw
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
  ${ZBAR_LIBRARIES}
)

add_executable(qrdetect src/qrdetect.cpp)
target_link_libraries(qrdetect
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
  ${ZBAR_LIBRARIES}
)

add_executable(imgqrdetect src/qrdetect_img.cpp)
target_link_libraries(imgqrdetect
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
  ${ZBAR_LIBRARIES}
)

add_executable(pr1basic src/pr1basic.cpp)
target_link_libraries(pr1basic
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
)

add_executable(pr1basic_ros src/pr1basic_ros.cpp)
target_link_libraries(pr1basic_ros
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
)

add_executable(pr1basic_ros_four src/pr1basic_ros_four.cpp)
target_link_libraries(pr1basic_ros_four
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
)

add_executable(pr2basic src/pr2basic.cpp)
target_link_libraries(pr2basic
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
  ${ZBAR_LIBRARIES}
)

add_executable(pr2low src/pr2low.cpp)
target_link_libraries(pr2low
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
  ${ZBAR_LIBRARIES}
)

add_executable(pr3basic src/pr3basic.cpp)
target_link_libraries(pr3basic
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
)

if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
add_executable(pr1basic_cu src/pr1basic_cu.cpp)
target_link_libraries(pr1basic_cu
  ${catkin_LIBRARIES}
  ${OpenCV_LIBRARIES}
)
endif()


add_executable(s2020basic 
    src/s2020basic.cpp
    src/mcu_correspond/mcu_data_subscriber.cpp)
target_link_libraries(s2020basic
  ${catkin_LIBRARIES}
  ${YAML_CPP_LIBRARIES}
  ${OpenCV_LIBRARIES}
)

# 0720
add_executable(g2021zbar 
    src/g2021zbar.cpp
    src/mcu_correspond/mcu_data_subscriber.cpp)
target_link_libraries(g2021zbar
  ${catkin_LIBRARIES}
  ${YAML_CPP_LIBRARIES}
  ${OpenCV_LIBRARIES}
  ${ZBAR_LIBRARIES}
)

# 0721
add_executable(g2021down 
    src/g2021down.cpp
    src/mcu_correspond/mcu_data_subscriber.cpp)
target_link_libraries(g2021down
  ${catkin_LIBRARIES}
  ${YAML_CPP_LIBRARIES}
  ${OpenCV_LIBRARIES}
  ${ZBAR_LIBRARIES}
)

# catkin_install_python(PROGRAMS scripts/pr1basic.py
#   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Declare a C++ library
# add_library(${PROJECT_NAME}
#   src/${PROJECT_NAME}/vision.cpp
# )

## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/vision_node.cpp)

## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")

## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Specify libraries to link a library or executable target against
# target_link_libraries(${PROJECT_NAME}_node
#   ${catkin_LIBRARIES}
# )